package com.ktgj.hotel.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.hotel.domain.DicElongCity;
import com.ktgj.hotel.domain.dic.DicCityList;
import com.ktgj.hotel.domain.vo.DicCountyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.hotel.domain.dic.DicCounty;
import com.ktgj.hotel.service.IDicCountyService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 市、区Controller
 * 
 * @author ruoyi
 * @date 2021-10-28
 */
@ControllerAdvice
@RestController
@RequestMapping("/county")
public class DicCountyController extends BaseController
{
    @Autowired
    private IDicCountyService dicCountyService;

    /**
     * 查询市、区列表
     */
    //@PreAuthorize(hasPermi = "hotel:county:list")
    @GetMapping("/list")
    public TableDataInfo list(DicCounty dicCounty)
    {
        startPage();
        List<DicCounty> list = dicCountyService.selectDicCountyList(dicCounty);
        return getDataTable(list);
    }

    /**
     * 导出市、区列表
     */
    //@PreAuthorize(hasPermi = "hotel:county:export")
    @Log(title = "市、区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DicCounty dicCounty) throws IOException
    {
        List<DicCounty> list = dicCountyService.selectDicCountyList(dicCounty);
        ExcelUtil<DicCounty> util = new ExcelUtil<DicCounty>(DicCounty.class);
        util.exportExcel(response, list, "市、区数据");
    }

    /**
     * 获取市、区详细信息
     */
    //@PreAuthorize(hasPermi = "hotel:county:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dicCountyService.selectDicCountyById(id));
    }

    /**
     * 新增市、区
     */
    //@PreAuthorize(hasPermi = "hotel:county:add")
    @Log(title = "市、区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DicCounty dicCounty)
    {
        return toAjax(dicCountyService.insertDicCounty(dicCounty));
    }

    /**
     * 修改市、区
     */
    //@PreAuthorize(hasPermi = "hotel:county:edit")
    @Log(title = "市、区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DicCounty dicCounty)
    {
        return toAjax(dicCountyService.updateDicCounty(dicCounty));
    }

    /**
     * 删除市、区
     */
    //@PreAuthorize(hasPermi = "hotel:county:remove")
    @Log(title = "市、区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dicCountyService.deleteDicCountyByIds(ids));
    }

    /**
     * 查询全部县信息(远程)
     * */
    @PostMapping("/allDicCountyList")
    public List<DicCountyVo> allDicCountyList() {
        List<DicCountyVo> dicCountyVoList = dicCountyService.selectAllDicCountyList();
        if (dicCountyVoList.size() > 0){
            return dicCountyVoList;
        }
        else {
            return null;
        }
    }

    /**
     * 跟据县、区名称查询信息（远程）
     * */
    @PostMapping("/countyId")
    public DicCountyVo countyId(@RequestParam("countyName") String countyName){
        DicCountyVo dicCountyVo = dicCountyService.selectDicCountyByDicCountyId(countyName);
        if (dicCountyVo != null){
            return dicCountyVo;
        }
        else {
            return null;
        }
    }

    @GetMapping("/queryCountyList")
    public AjaxResult queryCountyList() {
        List<DicCityList> dicCityLists = dicCountyService.queryCountyList();
        if (dicCityLists != null) {
            return AjaxResult.success(dicCityLists);
        } else {
            return AjaxResult.error("查询失败");
        }
    }

    /**
     * 根据市查询酒店筛选条件“行政区”
     * */
    @PostMapping("/conditionAdministrative")
    public AjaxResult conditionAdministrativeDistrict(@RequestBody Map<String, Object> map) {
        Long cityId = Long.valueOf(map.get("cityId").toString());
        List<DicCounty> dicCountyList = dicCountyService.conditionAdministrativeDistrict(cityId);
        if (dicCountyList != null){
            return AjaxResult.success(dicCountyList);
        }
        else {
            return AjaxResult.error("酒店筛选条件查询失败");
        }
    }

    /**
     * 酒店商圈列表
     * */
    @PostMapping("/county")
    public AjaxResult county(){
        List<DicCounty> dicCountyList = dicCountyService.county();
        return AjaxResult.success(dicCountyList);
    }
}
